﻿using System.Windows;
using System.Windows.Interactivity;

namespace BaseControls
{
    /// <summary>
    /// Behavior for moving clock when user click in wrong place (not item).
    /// </summary>
    public class ClockMove : Behavior<DependencyObject>
    {
        public ClockMove()
        {
        }
        public ClockMove(string parameter)
        {
            count = int.Parse(parameter);
        }
        private int count =  5;
        protected override void OnAttached()
        {
            Clock clock = FindClock();
            if (clock != null)
                clock.Time -= count;
            base.OnAttached();
        }
        private Clock FindClock()
        {
            UIElement frameControl = LogicalTreeHelper.FindName("FrameControl", (FrameworkElement)AssociatedObject);
            return ((IHudGameInterface)(frameControl as FrameworkElement)).GetClock();
        }
        protected override void OnDetaching()
        {
            base.OnDetaching();            
        }
    }
}